/*
 *  Copyright 2010 Wesley Gooch, Ryan Nix, Cody Wenzel.
 *  Montana State University - Spring Semester 2010
 *  Computer Science 450 - Compilers
 *  Project: Micro-Pascal Compiler
 */
package msu.compiler.errorhandling;

import msu.compiler.scanner.Token;

/**
 * Custom Exception class to simplify and encapsulate error handling.
 * @author Wesley
 */
public class CompileException extends RuntimeException {

    public Token token;

    public CompileException(String message) {
        super(message);
        ErrorHandler.disableCodeGeneration();
    }

    public CompileException(String message, Token token) {
        super(message);
        this.token = token;
        ErrorHandler.disableCodeGeneration();
    }

    public CompileException() {
        super();
        ErrorHandler.disableCodeGeneration();
    }

    @Override
    public String getMessage() {
         String message = "Error: " + super.getMessage();

        if(token != null) {
            message += " " + token.positionToString();
        }
        return message;
    }

    public void printMessage() {
       System.out.println(getMessage());
    }
}
